import { defHttp } from '@/utils/http/axios';
import {
  ModuleInfo,
  ModuleParams,
  ModuleListGetResultModel,
  ModuleAddReq,
  ModuleEditReq,
  ModuleDelReq,
  ModuleTypeInfo,
  ModuleTypeParams,
  ModuleTypeListGetResultModel,
  ModuleTypeAddReq,
  ModuleTypeEditReq,
  ModuleTypeDelReq,
  ModuleAttrInfo,
  ModuleAttrParams,
  ModuleAttrListGetResultModel,
  ModuleAttrAddReq,
  ModuleAttrEditReq,
  ModuleAttrDelReq,
} from './model/moduleModel';

enum Api {
  // Module
  List = '/api/admin/v1/module/list',
  Create = '/api/admin/v1/module/add',
  Update = '/api/admin/v1/module/edit',
  Delete = '/api/admin/v1/module/del',
  Info = '/api/admin/v1/module/info',
  // Module Type
  TypeList = '/api/admin/v1/module/type/list',
  TypeCreate = '/api/admin/v1/module/type/add',
  TypeUpdate = '/api/admin/v1/module/type/edit',
  TypeDelete = '/api/admin/v1/module/type/del',
  TypeInfo = '/api/admin/v1/module/type/info',
  // Module Attr
  AttrList = '/api/admin/v1/module/attr/list',
  AttrCreate = '/api/admin/v1/module/attr/add',
  AttrUpdate = '/api/admin/v1/module/attr/edit',
  AttrDelete = '/api/admin/v1/module/attr/del',
  AttrInfo = '/api/admin/v1/module/attr/info',
}

// Module APIs
export const getModuleList = (params: ModuleParams) =>
  defHttp.get<ModuleListGetResultModel>({
    url: Api.List,
    params,
    headers: { 'Content-Type': 'multipart/form-data' },
  });

export const createModule = (params: ModuleAddReq) =>
  defHttp.post<{ id: number }>({ url: Api.Create, params });

export const updateModule = (params: ModuleEditReq) =>
  defHttp.put<void>({ url: Api.Update, params });

export const deleteModule = (params: ModuleDelReq) =>
  defHttp.delete<void>({ url: Api.Delete, params });

export const getModuleInfo = (id: number) =>
  defHttp.get<ModuleInfo>({ url: Api.Info, params: { id } });

// Module Type APIs
export const getModuleTypeList = (params: ModuleTypeParams) =>
  defHttp.get<ModuleTypeListGetResultModel>({
    url: Api.TypeList,
    params,
    headers: { 'Content-Type': 'multipart/form-data' },
  });

export const createModuleType = (params: ModuleTypeAddReq) =>
  defHttp.post<{ id: number }>({ url: Api.TypeCreate, params });

export const updateModuleType = (params: ModuleTypeEditReq) =>
  defHttp.put<void>({ url: Api.TypeUpdate, params });

export const deleteModuleType = (params: ModuleTypeDelReq) =>
  defHttp.delete<void>({ url: Api.TypeDelete, params });

export const getModuleTypeInfo = (id: number) =>
  defHttp.get<ModuleTypeInfo>({ url: Api.TypeInfo, params: { id } });

// Module Attr APIs
export const getModuleAttrList = (params: ModuleAttrParams) =>
  defHttp.get<ModuleAttrListGetResultModel>({
    url: Api.AttrList,
    params,
    headers: { 'Content-Type': 'multipart/form-data' },
  });

export const createModuleAttr = (params: ModuleAttrAddReq) =>
  defHttp.post<{ id: number }>({ url: Api.AttrCreate, params });

export const updateModuleAttr = (params: ModuleAttrEditReq) =>
  defHttp.put<void>({ url: Api.AttrUpdate, params });

export const deleteModuleAttr = (params: ModuleAttrDelReq) =>
  defHttp.delete<void>({ url: Api.AttrDelete, params });

export const getModuleAttrInfo = (id: number) =>
  defHttp.get<ModuleAttrInfo>({ url: Api.AttrInfo, params: { id } });
